<template>
  <div class="app-container">
    <header class="app-header">
      <div class="header-content">
        <img src="/eggfriedrice-logo.svg" alt="蛋炒饭王国" class="header-logo" />
        <h1>蛋炒饭王国智能客服系统</h1>
      </div>
      <button class="btn-new-chat" @click="createNewChat">
        <span>+</span> 新增客服聊天
      </button>
    </header>

    <main class="app-main">
      <div class="welcome-section" v-if="chatWindows.length === 0">
        <div class="welcome-card">
          <img src="/chef-welcome.svg" alt="欢迎" class="welcome-image" />
          <h2>欢迎使用蛋炒饭王国智能客服</h2>
          <p>点击上方按钮开始与我们的智能客服对话</p>
          <p class="tip">您可以同时打开多个聊天窗口，每个窗口有独立的会话记忆</p>
          <button class="btn-start" @click="createNewChat">
            开始对话
          </button>
        </div>
      </div>
      
      <div class="chat-windows-container">
        <ChatWindow
          v-for="window in chatWindows"
          :key="window.memoryId"
          :memoryId="window.memoryId"
          @close="removeChatWindow"
          :style="{ position: 'relative' }"
        />
      </div>
    </main>

    <footer class="app-footer">
      <p>蛋炒饭王国 © 2024 - 为您提供美味的蛋炒饭和优质的服务</p>
    </footer>
  </div>
</template>

<script>
import ChatWindow from './components/ChatWindow.vue';
import chatService from './utils/ChatService';

export default {
  name: 'App',
  components: {
    ChatWindow
  },
  data() {
    return {
      chatWindows: []
    };
  },
  methods: {
    createNewChat() {
      const memoryId = chatService.generateMemoryId();
      this.chatWindows.push({
        memoryId,
        title: `客服对话 #${this.chatWindows.length + 1}`
      });
    },
    removeChatWindow(memoryId) {
      const index = this.chatWindows.findIndex(window => window.memoryId === memoryId);
      if (index > -1) {
        this.chatWindows.splice(index, 1);
      }
    }
  },
  beforeUnmount() {
    chatService.closeAllConnections();
  }
};
</script>

<style>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
  min-height: 100vh;
}

/* 确保所有输入框在全局范围内都能正确显示 */
input, textarea {
  background-color: #ffffff !important;
  color: #000000 !important;
  border: 1px solid #e0e0e0 !important;
  outline: none !important;
  box-shadow: none !important;
  -webkit-text-fill-color: #000000 !important;
  opacity: 1 !important;
  caret-color: #000000 !important;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
  color: white;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: white;
  padding: 4px;
}

.app-header h1 {
  font-size: 24px;
  font-weight: 600;
}

.btn-new-chat {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid white;
  color: white;
  padding: 10px 20px;
  border-radius: 25px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-new-chat:hover {
  background: white;
  color: #ff9800;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-new-chat span {
  font-size: 20px;
  font-weight: bold;
}

.app-main {
  flex: 1;
  padding: 24px;
  position: relative;
  min-height: calc(100vh - 120px);
}

.welcome-section {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  min-height: 400px;
}

.welcome-card {
  background: white;
  padding: 48px;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  text-align: center;
  max-width: 480px;
  border: 2px solid #ffb74d;
}

.welcome-image {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin-bottom: 24px;
  border: 4px solid #ff9800;
}

.welcome-card h2 {
  color: #ff9800;
  font-size: 28px;
  margin-bottom: 16px;
}

.welcome-card p {
  color: #666;
  font-size: 16px;
  margin-bottom: 8px;
}

.welcome-card .tip {
  font-size: 14px;
  color: #999;
  font-style: italic;
  margin-bottom: 24px;
}

.btn-start {
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 30px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 152, 0, 0.4);
}

.chat-windows-container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
}

.app-footer {
  background: #333;
  color: white;
  padding: 16px;
  text-align: center;
  font-size: 14px;
  margin-top: auto;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    gap: 16px;
    padding: 16px;
  }
  
  .app-header h1 {
    font-size: 20px;
  }
  
  .chat-windows-container {
    flex-direction: column;
    align-items: center;
  }
  
  .welcome-card {
    padding: 32px 24px;
    margin: 0 16px;
  }
}
</style>
